﻿using Autofac;
using NHibernate;
using ZenMoney.Core.DataAccess.Config;

namespace ZenMoney.Core.Container.Modules
{
	public class NHibernateModule : Module
	{
		protected override void Load(ContainerBuilder builder)
		{
			var config = NHibernateConfig.Build();
			var sessionFactory = config.BuildSessionFactory();

			builder.RegisterInstance(sessionFactory)
				.As<ISessionFactory>().SingleInstance();
			builder.Register(x => x.Resolve<ISessionFactory>().OpenSession())
				.As<ISession>().InstancePerLifetimeScope();
		}
	}
}
